import { createRouter, createWebHashHistory } from 'vue-router';

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/Login',
      name: 'Login',
      component: () => import('../views/Login.vue'),
    },
    {
      path: '/',
      name: 'home',
      component: () => import('../views/Home.vue'),
      redirect: '/IndexConfig',
      children:[
        {
          path: '/DylLink',
          name: 'DylLink',
          meta: {
            title: '抖音链接',
            icon: 'Link',
          },
          component: () => import('../views/DylLink.vue'),
        },
        {
          path: '/UserMessage',
          name: 'UserMessage',
          meta: {
            title: '用户信息',
            icon: 'User',
          },
          component: () => import('../views/UserMessage.vue'),
        },
        {
          path: '/IndexConfig',
          name: 'IndexConfig',
          meta: {
            title: '首页配置',
            icon: 'Setting',
          },
          component: () => import('../views/IndexConfig.vue'),
        },
        {
          path: '/MenuList',
          name: 'MenuList',
          meta: {
            title: '菜单列表',
            icon: 'List',
          },
          component: () => import('../views/MenuList.vue'),
        },
        {
          path: '',
          name: '',
          meta: {
            title: '商品',
            icon: 'Goods',
          },
          children: [
            {
              path: '/CreateGoods',
              name: 'CreateGoods',
              meta: {
                title: '新建商品',
                icon: 'Plus',
              },
              component: () => import('../views/CreateGoods.vue'),
            },
            {
              path: '/GoodsList',
              name: 'GoodsList',
              meta: {
                title: '商品列表',
                icon: 'List',
              },
              component: () => import('../views/GoodsList.vue'),
            }
          ]
        },
        {
          path: '/TagList',
          name: 'TagList',
          meta: {
            title: '标签列表',
            icon: 'List',
          },
          component: () => import('../views/TagList.vue'),
        },
        {
          path: '',
          name: '',
          meta: {
            title: '积分',
            icon: 'Coin',
          },
          children: [
            {
              path: '/CreateIntegralGoods',
              name: 'CreateIntegralGoods',
              meta: {
                title: '新建积分商品',
                icon: 'Plus',
              },
              component: () => import('../views/CreateIntegralGoods.vue'),
            },
            {
              path: '/IntegralList',
              name: 'IntegralList',
              meta: {
                title: '积分列表',
                icon: 'List',
              },
              component: () => import('../views/IntegralList.vue'),
            },
          ]
        },
        
        {
          path: '/OrdersList',
          name: 'OrdersList',
          meta: {
            title: '订单列表',
            icon: 'List',
          },
          component: () => import('../views/OrdersList.vue'),
        },
 
        

       
        // {
        //   path: '/GoodsList',
        //   name: 'GoodsList',
        //   component: () => import('../views/GoodsList.vue'),
        // },
        // {
        //   path: '/GoodsList/CreateGoods',
        //   name: 'CreateGoods',
        //   component: () => import('../views/CreateGoods.vue'),
        // },
 
      ]
    },
    
  ]
})

router.beforeEach((to, from,next) => {
  console.log(sessionStorage.token , '__')
  if (to.name !== 'Login' && (sessionStorage.token === "undefined" || sessionStorage.token == undefined)) next({ name: 'Login' })
  else next()
})

export default router
